/**
 * 住院页面JS
 * @author zyl
 */

/**
 * 住院页面数据表格属性配置
 */
$('#org_dataInHospitalGrid').datagrid({ 
	url:'statisticeinhospital/getStatisticeInhospitalByorgid',
	queryParams:{orgId:orange.getOrganizationData().id},
    singleSelect:true,
    rownumbers:true,
    columns:[[ 
        {field:'guid',title:'主键',hidden:true},
        {field:'month',title:'月份',width:'15%',halign:'center'},
        {field:'amountNormal',title:'正常出院人次',width:'15%',halign:'center'}, 
        {field:'amountDeath',title:'死亡出院人次',width:'15%',halign:'center'},
        {field:'amountArrearage',title:'欠费出院人次',width:'15%',halign:'center'},
        {field:'tcmPrescription',title:'住院中药方总数',width:'15%',halign:'center'},
        {field:'tcmPrescriptionEarnings',title:'住院中药方总金额',width:'23%',halign:'center'} 
    ]],
    pagination:true
});
// 验证添加输入的月份是否存在
function data_month_isExist() {
	var month = $('#add_dataInHospital_month').val();
	$.ajax({
        url:'statisticeinhospital/checkMonth',
        type: 'post',
        data: {
        	month:month,
        	orgGuid:orange.getOrganizationData().id
        	},
        success: function(data){
        	debugger;
        	if(data && data == true) {
        		$.messager.show({
        			title:'操作提示',
        			msg:'您所选择的月份已存在 ，请重新选择月份或者修改已有月份！！'
        		});
        	}
        }
	});
}
// 添加住院信息页面
function add_dataInHospital() {
	$('#add_dataInHospital').form('clear');
	$('#password-css').css({'display' : 'none'});
	$('input:radio[name="readonly"][value="0"]').prop('checked', true);
	$('#org_add_dataInHospital').window('open');
}
//修改住院页面信息
function update_dataInHospital() {
	$('#update_dataInHospital').form('clear');
	$('#password-css').css({'display':'none'});
	var doctorGrid = $("#org_dataInHospitalGrid");
	var selections = doctorGrid.datagrid("getSelections");
	if(selections.length == 0){
		$.messager.alert('提示','请选择需要修改的记录！'); 
	}else if(selections.length > 1){
		$.messager.alert('提示','请勿多选！'); 
	}else{
		var data = selections[0];
		var id = data.id;
		$('#update_dataInHospital').form('load', data);
		$('#org_update_dataInHospital').window('open');
	}
};
 // 添加住院信息页面确定按钮
function add_dataInHospital_saveOK() {
	var jsonData = orange.systemPage.getFormData('add_dataInHospital');
	jsonData['orgGuid'] = orange.getOrganizationData().id;
	var submitFlag = $('#org_add_dataInHospital').form('validate'); 
	if(submitFlag==true){
		data_month_isExist();
		$.ajax({
	        url:'statisticeinhospital/saveStatisticeInhospital',
	        type: 'post',
	        data: jsonData,
	        success: function(){
	        	$.messager.show({
	    			title:'提示',
	    			msg:'添加成功',
	    		});
	            $('#org_add_dataInHospital').window('close');
	            $('#org_dataInHospitalGrid').datagrid('reload');    
	        }
	    });
	}else{
		$.messager.alert('我的消息','不能保存，还有必填项未填写！');
		return;
	}
}
// 添加住院信息页面取消按钮
function add_dataInHospital_cancelOK() {
	$('#org_add_dataInHospital').window('close');
}
// 修改住院信息页面确定按钮
function update_dataInHospital_saveOK() {
	var jsonData = orange.systemPage.getFormData('update_dataInHospital');
	jsonData['orgGuid'] = orange.getOrganizationData().id;
	var submitFlag = $('#org_update_dataInHospital').form('validate'); 
	if(submitFlag==true){
		$.ajax({
	        url:'statisticeinhospital/saveStatisticeInhospital',
	        type: 'post',
	        data: jsonData,
	        success: function(){
	        	$.messager.show({
	    			title:'提示',
	    			msg:'修改成功',
	    		});
	            $('#org_update_dataInHospital').window('close');
	            $('#org_dataInHospitalGrid').datagrid('reload');    
	        }
	    });
	}else{
		$.messager.alert('我的消息','不能保存，还有必填项未填写！');
		return;
	}
}
// 修改住院信息页面取消按钮
function update_dataInHospital_cancelOK() {
	$('#org_update_dataInHospital').window('close');
}
// 设置添加住院信息页面初始化信息
$("#org_add_dataInHospital").window({
	width:'50%',
	collapsible: false,
	resizable: false
	});
// 设置添加住院信息页面初始化信息
$("#org_update_dataInHospital").window({
	width:'50%',
	collapsible: false,
	resizable: false
});

